/* 
    Purpose: Using the output from 1a_Census1960_fathers30to50.do,
    		    this file calculates two income ratios at the 
    		    race x south level:
				(1) Income of individuals not in labor force: lowest income of employed individuals
				(2) Income of individuals not in labor force: mean income of employed individuals 


    Note: The 1960 5% Census is big enough that it is not 
    	  necessary to weight averages. Perwt confirms that 
    	  everyone is assigned the same weight.

    Creates: UnemployedRatios_1960_raceXsouth.dta
*/
clear
set more off
cd "$Mydirectory1/1_DataSources/CensusData/"

*------------------------------------------------------------------------------------*
*------------------------------------------------------------------------------------*

* Bring in sample of 1960 Census fathers (black or white & aged 30-50)
	use ./input/Census1960_5pct_fathers30to50_adjustments.dta, clear 
	sum perwt, d 
	assert father==1 & age>=30 & age<=50 & race<=2
	
* Crosswalk 1950 occupations to coarsened ANES occupations
	clonevar occ1950_og = occ1950
	
	replace occ1950=. if occ1950>970
	merge m:1 occ1950 using ../Crosswalks/Crosswalk_1950Census_toANES.dta
	assert _merge!=1
	drop if _merge==2
	
/* Check out employment and labor force status 
   of those with missing occupation */
	tab labforce if occ1950==.
	tab empstat if occ1950==.
	tab empstat if occ1950==., nol
	
/* Among those with missing occupation, 
	keep people who are also NOT employed.*/
	drop if occ1950==. & empstat==1
	tab empstat if occ1950==. 
	assert labforce==1 if occ1950ej==99 
	
* If person unemployed or not in labor force, assign occ1950ej=99
	replace occ1950ej=99 if occ1950ej==. | empstat>1
	sum hh_income if occ1950ej==99, d
	sum hh_income if occ1950ej!=99, d
	
* Calculate mean income by race x south cell for working individuals
	foreach x in hh_income inctot ftotinc {	
		gen `x'_work = `x' if occ1950ej!=99
		bysort race south_merge: egen avg_`x'_byr_bys_work = mean(`x'_work)	
	}
	
* Calculate mean income for EVERYONE in an occupation x race x south cell
	gen number=1
	collapse (rawsum) number (mean) hh_income inctot ftotinc *_byr_bys_work, by(occ1950ej race south_merge) 
	
* Grab income of those that are unemployed
	local income "inctot"
	
	gen temp = `income' if occ1950ej==99
	bysort race south_merge: egen NILF_income = max(temp)
	
* Grab lowest income of employed people in race x south cell
	gen lowest_income_byr_bys =.
	foreach i in 0 1 {
		foreach j in 1 2 {	
			sum `income' if occ1950ej<99 & south_merge==`i' & race==`j'
			replace lowest_income=`r(min)' if south_merge==`i' & race==`j'
		}
	}
	
/* Calculate 2 ratios (at race x south level):
	(1) Income of individuals not in labor force: lowest income of employed individuals
	(2) Income of individuals not in labor force: mean income of employed individuals 
*/
	gen ratio_lowest = NILF_income / lowest_income_byr_bys
	bysort race south_merge: tab ratio_lowest
	
	gen ratio_avg = NILF_income / avg_`income'_byr_bys_work
	bysort race south_merge: tab ratio_avg
	
* Keep one observation per cell
	keep race south_merge ratio_lowest ratio_avg
	bysort race south_merge: keep if _n==1
	
	label var ratio_lowest "Ratio of not working to lowest income in race x south cell (`income')"
	label var ratio_avg "Ratio of not working to average income of working in race x south cell (`income')"
	
	compress
	save "./output/UnemployedRatios_1960_raceXsouth.dta", replace

	
